package com.dw.dwdzcommerce.view.details;

import com.dw.dwdzcommerce.R;
import com.dw.dwdzcommerce.base.activity.BaseActivity;
import com.dw.dwdzcommerce.entity.MainContentEntity;
import com.dw.dwdzcommerce.tools.uiView.smartMenu.SmartMenu;
import com.dw.dwdzcommerce.tools.uiView.smartMenu.SmartMenu.OnMenuClickListener;
import com.dw.dwdzcommerce.tools.uiView.xlistview.XListView.IXListViewListener;
import com.dw.dwdzcommerce.view.details.ActionBarLayout.OnActionBarClickListener;
import com.dw.dwdzcommerce.view.details.detailsPersenter.detailsPersenterInterface;
import com.dw.dwdzcommerce.view.details.lis.DetailsListAdapter;
import com.dw.dwdzcommerce.view.details.lis.ScrollListViewWithLoadMore;
import com.dw.dwdzcommerce.view.mainContent.MainContentFragment;
import com.dw.dwdzcommerce.view.mainContent.list.MainContentListAdapter;

import android.app.ActionBar;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Toast;

public class DetailsActivity extends BaseActivity
		implements OnActionBarClickListener, OnMenuClickListener, IXListViewListener ,detailsPersenterInterface{
	private ActionBarLayout mActionBarLayout;
	private MenuLayout mMenuLayout;
	private ScrollListViewWithLoadMore mListView;
	private StopHandler testHandler;
	private detailsPersenter mPerstener;

	
	@Override
	protected void inCreate(Bundle savedInstanceState) {
		mPerstener=new detailsPersenter();
		mPerstener.bind(this);
		mActionBarLayout = new ActionBarLayout();
		mMenuLayout = new MenuLayout();
		mMenuLayout.initModule(this);
		mActionBarLayout.initModule(this);
		mActionBarLayout.setmListener(this);
		mMenuLayout.setOnMenuClickListener(this);
//
		mListView = findView(R.id.activity_detail_content_lis);
		mListView.setPullLoadEnable(true);
		mListView.setPullRefreshEnable(true);
		mListView.setmListViewListener(this);
//
		MainContentEntity mData = MainContentFragment.generateTestData();
//		
//		
		DetailsListAdapter adapter=new DetailsListAdapter(mData, this);
		testHandler = new StopHandler(mListView);
//
		mListView.setAdapter(adapter);

	}

	@Override
	public void onAttachedToWindow() {
		super.onAttachedToWindow();
		mMenuLayout.end();

	}

	@Override
	protected int getLayoutId() {
		// TODO Auto-generated method stub
		return R.layout.activity_details;
	}

	@Override
	public void onSearchClick(View v) {
		toast(this, "to search");
	}

	@Override
	public void onBackClick(View v) {
		mPerstener.onBack();
	}

	@Override
	public void onMenuClick(String menu1, String menu2, String menu3) {
		Toast.makeText(this, "" + menu1 + " " + menu2 + " " + menu3, Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onRefresh() {
		testHandler.postDelayed(new Runnable() {

			@Override
			public void run() {
				testHandler.sendEmptyMessage(1);

			}
		}, 2000);
	}

	@Override
	public void onLoadMore() {
		testHandler.postDelayed(new Runnable() {

			@Override
			public void run() {
				testHandler.sendEmptyMessage(1);

			}
		}, 2000);
	}

	static class StopHandler extends Handler {
		ScrollListViewWithLoadMore mListView;

		public StopHandler(ScrollListViewWithLoadMore mListView) {
			this.mListView = mListView;
		}

		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			mListView.stopRefresh();
			mListView.stopLoadMore();

		}
	}

	@Override
	public void netWorkException(String msg) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void remoteFailMsg(String msg) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onComplete() {
		// TODO Auto-generated method stub
		
	}

}
